package com.epam.employeebase.command;

import org.apache.log4j.Logger;

import com.epam.employeebase.controller.RequestContent;
import com.epam.employeebase.dao.DAOFactory;
import com.epam.employeebase.dao.IEmployeeDAO;
import com.epam.employeebase.dao.exception.DAOException;

public final class ChooseDAOCommand implements Command{
	private static final Logger logger = Logger.getLogger(ChooseDAOCommand.class);
	private static final String DAO_PARAMETER_NAME = "dao";
	private static final String DAO_ATTRIBUTE_NAME = "dao";
	@Override
	public String execute(RequestContent requestContent) {
		
		String daoName = requestContent.getRequestParameter(DAO_PARAMETER_NAME);
		IEmployeeDAO dao = null;
		Command nextCommand = null;
		try {
			dao = DAOFactory.getEmployeeDao(daoName);
			requestContent.setSessionAttribute(DAO_ATTRIBUTE_NAME, dao);
			nextCommand = CommandManager.getCommand(CommandType.CHANGEENTRIESPERPAGE);
		} catch (DAOException e) {
			logger.error("DAOException", e);
		}
		
		return nextCommand.execute(requestContent);	
	}

}
